#!/usr/bin/perl
#Removes newlines from lexicon.tdl so it is one line for each entry

use Tie::File;
use strict;
use warnings;
use encoding 'utf8';

#Open file for writing
#open ONELINE, ">lexicon_oneline.tdl" or die $!;
open TRIMMED, ">lexicon_trim.tdl" or die $!;

#Open original lexicon.tdl
# tie my @lines, 'Tie::File', "lexicon.tdl" or die "Can't read file: $!\n";
 my $count=0;
# my $newlinecount=0;
 # foreach ( @lines )
 # {
    # if($_ =~ /^\s*$/){ # If line is only whitespace, preserve it
		# print ONELINE "\n";
		# print "Line ".$count." peserved \t";
		# print $newlinecount." empty lines found so far.\n";
		# $newlinecount++;
	# }
	# else{ # All other lines lose their newline-char
		# chomp ($_);
		# print ONELINE $_;
	#	print "Line ".$count." chomped\n"
	# }
  # $count++;
  # }
#Close files
# untie @lines;
# close ONELINE;

tie my @lexlines, 'Tie::File', "lexicon.tdl" or die "Can't read file: $!\n";
$count=0;
foreach ( @lexlines ){
	if($_ =~ m/^(.*)\s\:=(.*)$/){
	chop($2);
	chop($2);
	print $1."\t".$2."\n";	
		print TRIMMED $1."\t".$2."\n";
	}		
	$count++;
	#print $count."\n"
}
untie @lexlines;
close TRIMMED;
print "All done!\n";